package DomainObject;

import java.io.Serializable;
import java.util.ArrayList;

import org.omg.PortableServer.POA;

import combat5.Module;

import ca.etsmtl.log720.lab1.CollectionReactionPOA;
import ca.etsmtl.log720.lab1.Reaction;
import ca.etsmtl.log720.lab1.ReactionHelper;
///Create by Martin Soulière
@SuppressWarnings("serial")
public class CollectionReactionsImpl extends CollectionReactionPOA implements Serializable {

	private ArrayList<ReactionImpl> _reactions;
	public CollectionReactionsImpl() {
		_reactions = new ArrayList<ReactionImpl>();
	}
	public CollectionReactionsImpl(int[] listReactionID, ArrayList<ReactionImpl> reactions) {
		_reactions = new ArrayList<ReactionImpl>();
		for (int i = 0; i < listReactionID.length; i++) {
			for (int j = 0; j < reactions.size(); j++) {
				if (reactions.get(j).id() == listReactionID[i]) {
					_reactions.add(reactions.get(j));
					break;
				}
			}
		}
	}
	public Reaction getReaction(int index) {
		try {
			// Trouver la réaction correspondant au parametre "index"
			ReactionImpl reaction = _reactions.get(index);

			// REcuperer le POA cree dans le serveur
			POA rootpoa = Module._poa;

			// Activer l'objet et retourner l'objet CORBA
			org.omg.CORBA.Object obj = rootpoa.servant_to_reference(reaction);

			// Retourner une réactions
			return ReactionHelper.narrow(obj);
		} catch (Exception e) {
			return null;
		}
	}
	public int size() {
		return _reactions.size();
	}
	///retourne la collection de réations
	public ArrayList<ReactionImpl> getListeReactions() {
		return _reactions;
	}

}
